package com.sychip.fhc.app.drawer.nav


import androidx.lifecycle.viewModelScope
import com.sychip.fhc.MainApplication
import com.sychip.fhc.app.pref.PrefDataStoreIf
import  com.sychip.fhc.base.BaseAppViewModel
import  com.sychip.fhc.base.ViewModelStates
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject


/**
 * ViewModel for the Start screen.
 */
@HiltViewModel
class DrawerViewModel @Inject constructor(
    app : MainApplication,
    private val prefDataStore: PrefDataStoreIf,
) : BaseAppViewModel(app) {


    private val _testBooleanFlow = MutableStateFlow<Boolean>(false)
    val testBooleanFlow: StateFlow<Boolean> = _testBooleanFlow.asStateFlow()

    fun testBoolean(){
        _testBooleanFlow.update {!_testBooleanFlow.value}
    }


    init {
        prefDataStore.getUsbDevice().map { localUsb ->
            Timber.i(" prefDataStore   init  >>>>>>>>>>>>>>>>>>>>>>>>> ${localUsb==null} ")

        }.launchIn(viewModelScope)
        viewModelScope.launch {
            delay(5000)
            _testBooleanFlow.update {!_testBooleanFlow.value}
        }
    }

    override  fun initUICommonState():ViewModelStates{
        return ViewModelStates.Loading
    }


}


